const goodModel=require('../../models/webapp/good')
const cateModel=require('../../models/webapp/cate')
class GoodController{
    static async getGoodList(ctx){
        // let{hot,cate,name,min_price,max_price,status,size}=ctx.request.query
        let{page,size,cate}=ctx.request.query
        // 将查询条件放在一个集合中，方便修改
        const params={
            cate
        }
        if(!params.cate){
            delete params.cate;
        }
        // 结果是字符串类型的，需要转换
        size=parseInt(size||10)
        page=parseInt(page||1)
        const total=await goodModel.find(params).count()
        const list=await goodModel.find(params).limit(size).skip((page-1)*size)
        
        ctx.body={err:0,msg:'success',data:{total,list}}
        console.log(ctx.body,'0000000')
    }
    static async getAllCates(ctx){
        let list = await cateModel.find({})
	    ctx.body = { err:0, msg:'success', data: {list} }    
    }
    static async getGoodDetail(ctx){
        let {id}=ctx.request.query;
        let list = await goodModel.find({_id:id})
	    ctx.body = { err:0, msg:'success', data: {list} } 
    }
}
module.exports =GoodController